package com.ruoyi.student.service.impl;

import com.ruoyi.student.domain.Student;
import com.ruoyi.student.dto.StudentRepetitionDto;
import com.ruoyi.student.dto.StudentStateDto;
import com.ruoyi.student.mapper.StudentMapper;
import com.ruoyi.student.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生Service业务层处理
 * 
 * @author hoyo
 * @date 2022-12-28
 */
@Service
public class StudentServiceImpl implements IStudentService 
{
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询学生
     * 
     * @param id 学生主键
     * @return 学生
     */
    @Override
    public Student selectStudentById(Long id)
    {
        return studentMapper.selectStudentById(id);
    }

    /**
     * 查询学生列表
     * 
     * @param student 学生
     * @return 学生
     */
    @Override
    public List<Student> selectStudentList(Student student)
    {
        return studentMapper.selectStudentList(student);
    }

    /**
     * 新增学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int insertStudent(Student student)
    {
        return studentMapper.insertStudent(student);
    }

    /**
     * 修改学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int updateStudent(Student student)
    {
        return studentMapper.updateStudent(student);
    }

    /**
     * 批量删除学生
     * 
     * @param ids 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentByIds(Long[] ids)
    {
        return studentMapper.deleteStudentByIds(ids);
    }

    /**
     * 删除学生信息
     * 
     * @param id 学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentById(Long id)
    {
        return studentMapper.deleteStudentById(id);
    }

    /**
     * 批量修改学生状态
     *
     */
    @Override
    public void updateStudentState(StudentStateDto stateDto) {
        //获取ids
        Long[] ids = stateDto.getIds();
        for (Long id : ids) {
            //获取其中id
            Student studentById = studentMapper.selectStudentById(id);
            //修改状态
            studentById.setStates(stateDto.getStates());
            studentById.setInterviewTest(stateDto.getInterviewTest());
            studentById.setFinalTest(stateDto.getFinalTest());
            studentMapper.updateStudent(studentById);
        }

    }

    /**
     * 留级转班
     * @param repetitionDto
     */
    @Override
    public void repetition(StudentRepetitionDto repetitionDto) {
        //获取当前学生状态
        Long id = repetitionDto.getId();

        Student student = studentMapper.selectStudentById(id);
        student.setStates(repetitionDto.getStates());
        //student.setRemark(repetitionDto.getRemark());
        student.setGrade(repetitionDto.getGrade());
        studentMapper.updateStudent(student);

    }
}
